package br.edu.ufcg.msnlab2.grupo07.monteCarlo;

import br.edu.ufcg.msnlab2.MSNLabException;


/**
 * This class represents a result of the Monte Carlo's method. It
 * contains the integration estimative and also its variance.
 * @author David Candeia 
 * @author Felipe Leal
 *
 */
public class MonteCarloResult {
	
	private double error;
	private double integrationResult;
	
	/**
	 * Constructor
	 * @param variance The error of the integration estimative
	 * @param integrationResult The estimative of the integration
	 */
	public MonteCarloResult(double variance, double integrationResult){
		this.error = variance;
		this.integrationResult = integrationResult;
	}
	
	/**
	 * This method returns the error of the integration estimative  
	 * @return The estimative error
	 */
	public double getError() {
		return error;
	}
	
	/**
	 * This method returns the integration estimative
	 * @return The integration estimative
	 */
	public double getIntegrationResult() {
		return integrationResult;
	}

	/**
	 * This method is responsible for changing the integration result
	 * of the Monte Carlo Method
	 * @param newResult The new integration estimative
	 * @throws MSNLabException Exception thrown if an invalid estimative
	 * is being used.
	 */
	public void setIntegrationResult(double newResult) throws MSNLabException {
		if(newResult <= 0){
			throw new MSNLabException("Integration result can not be negative or zero!");
		}
		integrationResult = newResult;
	}

	/**
	 * This method is responsible for changing the estimative of the 
	 * error for the integral estimative calculated
	 * @param error The new error estimative value
	 */
	public void setError(double error) {
		this.error = error;
	}

	public String toString(){
		return "ES: "+integrationResult+" ERROR: "+error;
	}
}
